﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Engine.Behavior;
using Engine.Input;
using Engine.Commands;
using Microsoft.Xna.Framework.Input;

namespace Engine.Behavior
{
    public class KeyboardBehaviors : IBehaviors
    {
        private CommandProcessor CommandProcessor = CommandProcessor.getCommandProcessor();
        private IDictionary<IInput, IBehavior> _mapbehavior = new Dictionary<IInput, IBehavior>();
        private IDictionary<IInput, String> _mapbehaviorActDirect = new Dictionary<IInput, String>();
        private IDictionary<String, IInput> _mapbehavioractReverse = new Dictionary<String, IInput>();
            
        public void MapKeyBehavior(Keys key, StateKey state,IBehavior beh , String act)
        {

            InputPlayableKeyBoard ip1 = new SimpleConcreteKeyboardInputPlayable(state, key, Behave, EntityType.IOBJECT);
            _mapbehavior[ip1] = beh;
            _mapbehavioractReverse[act] = ip1;
            _mapbehaviorActDirect[ip1] = act;
            BindKeyCommand bkc1 = new BindKeyCommand(ip1, BindAction.ADD);
            this.CommandProcessor.SendCommandSyncronous(bkc1); 
            
        }

        public void RemoveMapKeyBehavior(String act)
        {
            _mapbehavior.Remove(_mapbehavioractReverse[act]);
            _mapbehaviorActDirect.Remove(_mapbehavioractReverse[act]);
            BindKeyCommand bkc1 = new BindKeyCommand(_mapbehavioractReverse[act] as InputPlayableKeyBoard, BindAction.REMOVE);
            this.CommandProcessor.SendCommandSyncronous(bkc1); 
            _mapbehavioractReverse.Remove(act);
        }

        void Behave(InputPlayableKeyBoard ipk)
        {
            _mapbehavior[ipk].PerformBehavior(_mapbehaviorActDirect[ipk]);
        }




     
    }
}
